﻿@model CleverCMS.Blog.Services.ViewModels.BlogEntryCategoryEditModel

@{
    Layout = "~/Areas/CleverCms.Admin/Views/Shared/_Layout.cshtml";
}

@section TitleContent
{
    @((Model != null && Model.Category != null) ? "Edit Category" : "New Category")
}

@section HeadContent
{
    <script type="text/javascript">
        $(document).ready(function () {
            $('#Category_Picture').val();
            $('.icon').each(function () {
                if ($('#Category_Picture').val() == $(this).attr('value')) {
                    $(this).addClass('selected');
                    return false;
                }
            });
            
            $("button[type=submit]").on("click", function () {
                $("html, body").animate({ scrollTop: 0 }, "slow");
            });
        });
        
        $('#Category_Picture').keypress (function (e) {
            if (e.keyCode < 48 || e.keyCode > 57) {
                return false;
            }
        });
        
        $('#Category_Picture').click(function () {
            $('#pictures_block').show();
        });
        
        $('.icon').click(function() {
            $('#Category_Picture').val($(this).attr('value'));
            $('#pictures_block').hide();
            if ($('.selected').length) {
                $('.selected').each(function () {
                    $(this).removeClass('selected');
                });
            };
            $(this).addClass('selected');
        });

        function successSave(e) {
            if (e.success) {
                $("#failureResult").hide();
                $("#successResult").show().fadeOut(5000);
            } else {
                $("#errortext").html(e.error);
                $("#failureResult").fadeIn(1000);
            }
        }
        function failureSave() {
            $("#failureResult").show().fadeIn(700);
        }
    </script>
}

<div class="widget green">
    <div class="widget-title">
        <h4><i class="icon-reorder"></i> Category</h4>
    </div>
    <div class="widget-body">
        
        <div id="failureResult" class="alert alert-block alert-error" style="display: none">
            <h4 class="alert-heading">Error!</h4>
            <p id="errortext">
            </p>
        </div>

        <div class="alert alert-block alert-success" style="display: none" id="successResult">
            <h4 class="alert-heading">Success!</h4>
            <p>
                Items was successfully saved.
            </p>
        </div>

        @using (Ajax.BeginForm("EditCategory", "Blog", new AjaxOptions { HttpMethod = "POST", OnFailure = "failureSave", OnSuccess = "successSave" }, new { id = "editCategoryForm", @class = "search_form general_form" }))
        {
            @Html.HiddenFor(model => model.Category.Id)
            
            <div class="row-fluid">
                <div class="span1">
                    <label class="pull-right">Alias:</label>           
                </div>
                <div class="span10">
                    @Html.TextBoxFor(model => model.Category.Alias)        
                </div>
            </div>
                
            <div class="row-fluid">
                <div class="span1">
                    <label class="pull-right">Name:</label>           
                </div>
                <div class="span10">
                    @Html.TextBoxFor(model => model.Category.CategoryName)       
                </div>
            </div>@*
                
                <div class="row-fluid">
                    <div class="span1">
                        <label class="pull-right">Picture:</label>           
                    </div>
                    <div class="span10">
                        @Html.TextBoxFor(model => model.Category.Picture)      
                    </div>
                </div>*@
                
            <div class="row-fluid">
                <div class="span1">
                    <label class="pull-right">Picture:</label>           
                </div>
                <div class="span10">
                    @Html.TextBoxFor(model => model.Category.Picture)      
                </div>
                <div id="pictures_block">
                    <span class="icon" value=""></span>
                    @{
                        foreach (string picture in Model.Pictures)
                        {
                            <span class="icon" value="@picture"><i class="icon-@picture"></i></span>
                        }
                    }
                </div>
            </div>
                
            <div class="row-fluid">
                <div class="span1">
                    <label class="pull-right">Sort order:</label>           
                </div>
                <div class="span10">
                    @Html.TextBoxFor(model => model.Category.SortOrder)    
                </div>
            </div>

            <div class="row-fluid">
                <div class="span1">
                    <label class="pull-right">Is Active:</label>           
                </div>
                <div class="span10">
                    @Html.CheckBoxFor(model => model.Category.IsActive)   
                </div>
            </div>
                
            <div class="row-fluid">
                <div class="span10 offset1">
                    <div class="submit_link">
                        <button type="submit" class="btn btn-success" name="save_post"><i class="icon-ok icon-white"></i> Publish</button>
                    </div>           
                </div>
            </div>    
        }
    </div>
</div>